#region Apache License
//
// Licensed to the Apache Software Foundation (ASF) under one or more 
// contributor license agreements. See the NOTICE file distributed with
// this work for additional information regarding copyright ownership. 
// The ASF licenses this file to you under the Apache License, Version 2.0
// (the "License"); you may not use this file except in compliance with 
// the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
#endregion


using System;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.ComponentModel;

namespace IPSim.GUI.Devices
{
    /// <author>Edward Smit</author>
    public abstract class BaseDevice
    {
        #region Members

        protected Point             location;
        protected Size              size;
        protected Color             borderColor = Color.Black;
        protected int               borderWidth = 1;
        protected DeviceCollection  connectors = new DeviceCollection();
        protected int               connectorSize = 4;
        protected string            name = "";

        #endregion

        #region Methods

        protected BaseDevice() 
        { 
        }

        internal abstract void Draw(Graphics g);
        
        internal virtual void UpdateConnectorsPosition()
        {
        }

        internal Rectangle GetRectangle()
        {
            return new Rectangle(location, size);
        }


        #endregion

        #region Properties


        [Category("Device")]
        [Browsable(true)]
        [Description("Device name")]
        public string Name
        {
            get
            {
                return name;
            }
            set
            {
                name = value;
            }
        }

        [Category("Device")]
        [Browsable(true)]
        [Description("Device type")]
        public string Type
        {
            get
            {
                return this.GetType().Name;
            }
        }

        [Browsable(false)]
        public virtual Point Location
        {
            get
            {
                return location;
            }
            set
            {
                location = value;
                UpdateConnectorsPosition();
                OnAppearanceChanged(new EventArgs());
            }
        }

        [Browsable(false)]
        public virtual Size Size
        {
            get
            {
                return size;
            }
            set
            {
                size = value;
                OnAppearanceChanged(new EventArgs());
            }
        }

        [Browsable(false)]
        public virtual Color BorderColor
        {
            get
            {
                return borderColor;
            }
            set
            {
                borderColor = value;
                OnAppearanceChanged(new EventArgs());
            }
        }

        [Browsable(false)]
        public virtual int BorderWidth
        {
            get
            {
                return borderWidth;
            }
            set
            {
                borderWidth = value;
                OnAppearanceChanged(new EventArgs());
            }
        }

        [Browsable(false)]
        public virtual DeviceCollection Connectors
        {
            get
            {
                return connectors;
            }
        }

        #endregion

        #region Events

        public event EventHandler AppearanceChanged;

        protected virtual void OnAppearanceChanged(EventArgs e)
        {
            if (AppearanceChanged != null)
                AppearanceChanged(this, e);
        }

        #endregion

    }
}
